#include "graphics/scene.h"
#include "main/rotation.h"
#include "settings/settings.h"
#include <QPainter>

Scene::Scene(QWidget *parent) :
    QWidget(parent)
{
    image = QImage();
    QObject::connect(Rotation::instance(), SIGNAL(onPoints(const unsigned char*)), this, SLOT(sPoints(const unsigned char*)));
}

void Scene::paintEvent(QPaintEvent *event)
{
	QPainter painter(this);
    int x = Settings::instance()->getSize(); int y = x, w, h;
    QSize size =this->size();
    w = size.rwidth(); h = size.rheight();
    image = QImage(gen_pkt, x, y, QImage::Format_RGB888);
	painter.setBackground(QBrush(QColor(255,255,255)));
    painter.drawImage(QPoint(w/32,h/32), image);
}

void Scene::sPoints(const unsigned char *generated)
{
	gen_pkt = generated;
	this->repaint();
}

void Scene::sSceneRepaint()
{
    this->repaint();
}

QImage Scene::getImage() const
{
	return image;
}

void Scene::mousePressEvent(QMouseEvent *event)
{
	if(Qt::LeftButton == event->button())
	{
		Settings::instance()->setSourcePosition(0, event->pos().x(), event->pos().y());
	}
	else
	{
		Settings::instance()->setSourcePosition(1, event->pos().x(), event->pos().y());
	}
}
